<template>
    <el-container class="project-second-step-view">
        <el-main>
            <span>
                <h5>项目版本管理</h5>
                <el-button icon="el-icon-plus" @click="addProjectVersion">添加版本</el-button>
            </span>
            <h5 v-if="isNoVersionChange">暂无版本变动可以直接跳下一步。</h5>
            <el-form v-else label-width="100px" v-model="addVersion">
                <el-form-item label="版本号">
                    <el-input v-model="addVersion.version"></el-input>
                </el-form-item>
                <el-form-item label="版本描述">
                    <el-input v-model="addVersion.desc"></el-input>
                </el-form-item>
                <el-form-item label="版本类型">
                    <el-input v-model="addVersion.type"></el-input>
                </el-form-item>
            </el-form>
            <version-list/>
        </el-main>
        <el-footer>
            <el-button @click="saveAndNextStep">下一步</el-button>
            <el-button @click="back">返回</el-button>
        </el-footer>
    </el-container>
</template>
<script>

    import VersionList from "../../version/VersionList";

    export default {
        components: {
            VersionList,
        },
        name: 'ProjectSecondStep',
        component: {
            VersionList: () => import('@/views/version/VersionList.vue')
        },
        data: function () {
            return {
                projectId: '',
                isNoVersionChange: true,
                addVersion: {
                    version: '',
                    desc: '',
                    project: '',
                    type: '',
                    updateTime: '',
                    handler: ''
                }
            }
        },
        created: function () {
            this.projectId = this.$route.query.projectId;
        },
        methods: {
            saveAndNextStep: function () {
                this.$router.push({name: 'add-project-third-step'});
            },
            back: function () {
                this.$router.back();
            },
            addProjectVersion: function () {
                let self = this;
                let url = '/api/version/add';
                self.project.project = self.projectId;
                this.$http.post(url, self.project).then(res => {
                    this.$router.push({
                        name: 'add-project-third-step',
                        query: {
                            projectId: res.id
                        }
                    });
                }).catch(err => {
                    console.log(err);
                });
            }
        }
    }
</script>
